package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.HdBean;
import com.oscar.ehome.bean.pagebean.InsuranceBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.util.DateUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/8/31
 * 保单列表
 */

public class InsuranceAdapter extends BaseAdapter {

    private List<InsuranceBean.ListInuranceBean> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    InsuranceBean.ListInuranceBean bean;


    public InsuranceAdapter(Context context, List<InsuranceBean.ListInuranceBean> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<InsuranceBean.ListInuranceBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_insuance, null);
            holder = new ViewHolder();
            holder.toubbao_people_text = (TextView) convertView.findViewById(R.id.toubbao_people_text);
            holder.toubbao_phone_text = (TextView) convertView.findViewById(R.id.toubbao_phone_text);
            holder.insurance_time = (TextView) convertView.findViewById(R.id.insurance_time);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            if (list.get(position) != null) {
                bean = list.get(position);
                if (bean.getCreateDate() != null) {
                    holder.insurance_time.setText(bean.getCreateDate());
                } else {
                    holder.insurance_time.setText("暂无");
                }
                if (bean.getInsuredPerson() != null) {
                    holder.toubbao_people_text.setText(bean.getInsuredPerson());
                } else {
                    holder.toubbao_people_text.setText("暂无");
                }
                if (bean.getMobile() != null) {
                    holder.toubbao_phone_text.setText(bean.getMobile());
                } else {
                    holder.toubbao_phone_text.setText("暂无");
                }
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView toubbao_people_text;//投保人
        TextView toubbao_phone_text;//投保人电话
        TextView insurance_time;//时间
    }
}
